//
//  ZH_ClassPersonTableViewCell.m
//  WisdomStar
//
//  Created by zhangliwen on 2018/10/25.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_ClassPersonTableViewCell.h"
@interface ZH_ClassPersonTableViewCell()
@property (nonatomic,weak)UIImageView *photoImage;
@property (nonatomic,weak)UILabel *nameLabel;
@property (nonatomic,weak)UIButton *typeButton;
@property (nonatomic,weak)UILabel *levelLabel;
@property (nonatomic,weak)UIButton *classButton;
@property (nonatomic,weak)UILabel *moneyLabel;
@end
@implementation ZH_ClassPersonTableViewCell

///创建
+(instancetype)cellWithTableView:(UITableView*)tableView
{
    static NSString *ID = @"ZH_ClassPersonTableViewCell";
    ZH_ClassPersonTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if(cell == nil){
        cell = [[ZH_ClassPersonTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}
///初始化
-(void)initDefault
{
    [self unShowClickEffect];
    self.bottomLongLineImage.hidden = NO;
}
- (void)loadSubviewConstraints{
    [self.photoImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(FITSCALE(15));
        make.centerY.equalTo(self.contentView);
        make.width.mas_equalTo(FITSCALE(71));
        make.height.mas_equalTo(FITSCALE(71));
        make.left.equalTo(self.contentView).offset(FITSCALE(12));
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(FITSCALE(24));
        make.left.equalTo(self.photoImage.mas_right).offset(FITSCALE(12));
    }];
    [self.typeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.nameLabel);
        make.right.equalTo(self.contentView).offset(FITSCALE(-12));
        make.width.mas_equalTo(FITSCALE(56));
        make.height.mas_equalTo(FITSCALE(22));
    }];
    [self.levelLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom).offset(FITSCALE(28));
        make.left.equalTo(self.nameLabel);
    }];
    [self.classButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.levelLabel);
        make.left.equalTo(self.levelLabel.mas_right).offset(FITSCALE(15));
        make.width.mas_equalTo(FITSCALE(66));
        make.height.mas_equalTo(FITSCALE(22));
    }];
    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(FITSCALE(-12));
        make.centerY.equalTo(self.levelLabel);
    }];
}
- (void)updataUI:(NSDictionary *)data{
    if (data) {
        [self.photoImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",SERVER_TEST,data[@"image"]]] placeholderImage:nil];
        if (![data[@"nickname"] isKindOfClass:[NSNull class]]) {
            self.nameLabel.text = data[@"nickname"];
        }
        NSString *string = [NSString stringWithFormat:@"%@",data[@"is_verify"]];
        if ([string isEqualToString:@"1"]) {
            [self.typeButton setTitle:@"已认证" forState:UIControlStateNormal];
        }
        else{
            [self.typeButton setTitle:@"未认证" forState:UIControlStateNormal];
        }
        self.levelLabel.text = data[@"level"];
        [self.classButton setTitle:data[@"cate_name"] forState:UIControlStateNormal];
        self.moneyLabel.text = [NSString stringWithFormat:@"￥%@/小时",data[@"price"]];
    }
}
#pragma mark - getter,setter
- (UIImageView *)photoImage{
    if (!_photoImage) {
        UIImageView *image = [UIImageView createImageViewWithName:@""];
        image.backgroundColor = [UIColor redColor];
        image.layer.cornerRadius = FITSCALE(35);
        image.layer.masksToBounds = YES;
        image.clipsToBounds = YES;
        [self.contentView addSubview:_photoImage = image];
    }
    return _photoImage;
}
- (UILabel *)nameLabel{
    if (!_nameLabel) {
        UILabel *label = [UILabel createLabelWithText:@"老师名/机构名..." font:kFontSize_28];
        [self.contentView addSubview:_nameLabel = label];
    }
    return _nameLabel;
}
- (UIButton *)typeButton{
    if (!_typeButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"已认证" target:self action:nil];
        button.backgroundColor = [UIColor colorWithHexString:@"#CBFFF8"];
        [button setTitleColor:[UIColor colorWithHexString:@"#00C9AE"] forState:UIControlStateNormal];
        button.layer.cornerRadius = FITSCALE(10);
        button.layer.masksToBounds = YES;
        button.clipsToBounds = YES;
        button.titleLabel.font = kFontSize_26;
        [self.contentView addSubview:_typeButton = button];
    }
    return _typeButton;
}
- (UILabel *)levelLabel{
    if (!_levelLabel) {
        UILabel *label = [UILabel createLabelWithText:@"V2中级" font:kFontSize_26];
        [self.contentView addSubview:_levelLabel = label];
    }
    return _levelLabel;
}
- (UIButton *)classButton{
    if (!_classButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"音乐" target:self action:nil];
        button.backgroundColor = kFontColorWhite;
        [button setTitleColor:[UIColor colorWithHexString:@"#00C9AE"] forState:UIControlStateNormal];
        button.layer.cornerRadius = FITSCALE(10);
        button.layer.borderWidth = FITSCALE(1);
        button.layer.borderColor = [UIColor colorWithHexString:@"#00C9AE"].CGColor;
        button.layer.masksToBounds = YES;
        button.clipsToBounds = YES;
        button.titleLabel.font = kFontSize_26;
        [self.contentView addSubview:_classButton = button];
    }
    return _classButton;
}
- (UILabel *)moneyLabel{
    if (!_moneyLabel) {
        UILabel *label = [UILabel createLabelWithText:@"￥400元/小时" font:kFontSize_26];
        label.textColor = [UIColor colorWithHexString:@"#FF4242"];
        label.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:_moneyLabel = label];
    }
    return _moneyLabel;
}
@end
